module(...,package.seeall)

local gameNetwork = require "gameNetwork"
local loggedIntoGC = false


function startGameCenter()

	-- called after the "init" request has completed
	local function initCallback( event )
    	if event.data then
        	loggedIntoGC = true
        	--native.showAlert( "Success!", "User has logged into Game Center", { "OK" } )
    	else
        	loggedIntoGC = false
        	--native.showAlert( "Fail", "User is not logged into Game Center", { "OK" } )
    	end
	end

	-- function to listen for system events
	local function onSystemEvent( event ) 
    	if event.type == "applicationStart" then
        	gameNetwork.init( "gamecenter", initCallback )
        	return true
    	end
	end
	Runtime:addEventListener( "system", onSystemEvent )

end

function showLeaderBoard()
	print("Show Leader Board")
	
	local function dismissCallback()
		print("Close leader board")
	end
	
	if (loggedIntoGC == true) then
		gameNetwork.show( "leaderboards", { leaderboard = {timeScope="Week"}, listener=dismissCallback } )	
	
	end
end


function setHighScore(scorevalue)
	print("Set High Score")
	
	local function requestCallback()
		print("call back from request")
	end
	
	if (loggedIntoGC == true) then
		gameNetwork.request( "setHighScore",
		{
    		localPlayerScore = { category="mainboard", value=scorevalue },
    		listener=requestCallback
		})
	end
end